import { h, Time } from "koishi"

export const name = "早睡提醒"

export function apply(ctx) {
  {
    let last = -Infinity
    ctx.user("3470524928").middleware(async (session, next) => {
      const now = new Date()
      if (+now - last < 15 * Time.minute) return next()
      const hour = now.getHours()
      if (hour === 23 || hour < 5) {
        await session.observeChannel(["locales"]).catch(e => ctx.logger.warn(e))
        last = +now
        if (hour === 23) session.send([h.at(session.userId), " ", ...h.parse(session.text("lnnbot.早睡提醒.lnn.eleven-oclock"))])
        else session.send([h.at(session.userId), " ", ...h.parse(session.text("lnnbot.早睡提醒.lnn.after-midnight", [hour % 12 || 12]))]);
      }
      return next()
    }, true)
    ctx.i18n.define("zh-CN", "lnnbot.早睡提醒.lnn", { "eleven-oclock": "11点多了，该睡了", "after-midnight": '{0}点多了还不睡觉，你在干甚么<face id="11"/>' })
  }
}
